#include<iostream>
using namespace std;
int Printnumroot(int n)
{
    int sum = 0;
    while (n)
    {
        sum += n % 10;
        n /= 10;
        if (n == 0 && sum / 10 != 0)
        {
            n = sum;
            sum = 0;
        }
    }
    return sum;
}
int main()
{
    string str;
    while (cin >> str)
    {
        int n = 0;
        for (const auto& ch : str)
            n += ch - '0';
        int ret = Printnumroot(n);
        cout << ret << endl;
    }
    return 0;
}